//
//  EFReturnGoodsAllViewCell.m
//  EnjogFood
//
//  Created by guocheng on 2017/5/24.
//  Copyright © 2017年 wf. All rights reserved.
//

#import "EFReturnGoodsAllViewCell.h"
#import "EFReturnGoodsAllViewItem.h"

@interface EFReturnGoodsAllViewCell ()

@property(nonatomic, strong)UIButton *selectButton;
@property(nonatomic, strong)UILabel *allTipsLabel;
@property(nonatomic, strong)UILabel *priceLabel;

@end

@implementation EFReturnGoodsAllViewCell



-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [UIColor clearColor];
        self.backgroundColor =  [UIColor clearColor];
        [self initView];
    }
    return self;
}

- (void)initView{
    [self.contentView addSubview:self.selectButton];
    [self.contentView addSubview:self.allTipsLabel];
    [self.contentView addSubview:self.priceLabel];
    
}


- (void)setObject:(EFReturnGoodsAllViewItem *)item{
    [super setObject:item];
    self.selectButton.selected = item.selected;
    
    NSString* totalPrice = [NSString stringWithFormat:@"总价¥%@",item.totalPrice];
    
    NSMutableAttributedString * strPrice = [[NSMutableAttributedString alloc]initWithString:totalPrice];
    NSRange range = NSMakeRange(0,2);
    [strPrice addAttribute:NSForegroundColorAttributeName value:kBlack333 range:range];
    [self.priceLabel setAttributedText:strPrice];
    [self.priceLabel sizeToFit];
    
    self.priceLabel.left = kScreenWidth - self.priceLabel.width - 20;
    
}

- (void)layoutSubviews{
    [super layoutSubviews]; 
    self.selectButton.left = scale(18.f);
    self.selectButton.top = scale(20.f);
    
    self.allTipsLabel.left = self.selectButton.right +scale(10.f);
    self.allTipsLabel.top = scale(24.f);
    
    self.priceLabel.left = kScreenWidth - self.priceLabel.width - 20;
    self.priceLabel.top = scale(24.f);
}


-(void)onClickSelectBtn{
    self.selectButton.selected = !self.selectButton.selected;
    if(self.selectblock){
        self.selectblock(self.selectButton.selected);
    }
} 

- (UIButton *)selectButton{
    if (!_selectButton) {
        _selectButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 22.f, 22.f)];
        [_selectButton setImage:IMG(@"cartlist_Unselected_icon") forState:UIControlStateNormal];
        [_selectButton setImage:IMG(@"cartlist_selected_icon") forState:UIControlStateSelected];
        [_selectButton setImage:IMG(@"cartlist_failure_icon") forState:UIControlStateDisabled];
        [_selectButton addTarget:self action:@selector(onClickSelectBtn) forControlEvents:UIControlEventTouchUpInside];
    }
    return _selectButton;
}


- (UILabel *)allTipsLabel{
    if (!_allTipsLabel) {
        _allTipsLabel = [[UILabel alloc] init];
        _allTipsLabel.backgroundColor = [UIColor clearColor];
        _allTipsLabel.font = [UIFont systemFontOfSize:13.f];
        _allTipsLabel.textColor = kBlack333;
        [_allTipsLabel setText:@"全选"];
        [_allTipsLabel sizeToFit];
        
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onClickSelectBtn)];
        [_allTipsLabel addGestureRecognizer:tapGesture];
        _allTipsLabel.userInteractionEnabled = YES;
    }
    return _allTipsLabel;
}


- (UILabel *)priceLabel{
    if (!_priceLabel) {
        _priceLabel = [[UILabel alloc] init];
        _priceLabel.backgroundColor = [UIColor clearColor];
        _priceLabel.font = [UIFont systemFontOfSize:13.f];
        _priceLabel.textColor = RGBCOLOR(0x69BA45);
    }
    return _priceLabel;
}




@end
